package com.elai.tags.controller;

import java.util.List;

import com.elai.common.annotation.Log;
import com.elai.common.core.domain.AjaxResult;
import com.elai.common.core.page.TableDataInfo;
import com.elai.common.enums.BusinessType;
import com.elai.common.utils.poi.ExcelUtil;
import com.elai.tags.service.BaseUserTagsLevelService;
import com.elai.common.core.controller.BaseController;
import com.elai.tags.domain.BaseUserTagsLevelDO;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 分级配置Controller
 *
 * @author elai
 * @date 2021-06-27
 */
@RestController
@RequestMapping("/tag/level")
public class BaseUserTagsLevelController extends BaseController
{
    @Autowired
    private BaseUserTagsLevelService baseUserTagsLevelService;

    /**
     * 查询分级配置列表
     */
    @PreAuthorize("@ss.hasPermi('tag:level:list')")
    @GetMapping("/list")
    public TableDataInfo list(BaseUserTagsLevelDO baseUserTagsLevel)
    {
        startPage();
        List<BaseUserTagsLevelDO> list = baseUserTagsLevelService.selectBaseUserTagsLevelList(baseUserTagsLevel);
        return getDataTable(list);
    }

    /**
     * 导出分级配置列表
     */
    @PreAuthorize("@ss.hasPermi('tag:level:export')")
    @Log(title = "分级配置", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(BaseUserTagsLevelDO baseUserTagsLevel)
    {
        List<BaseUserTagsLevelDO> list = baseUserTagsLevelService.selectBaseUserTagsLevelList(baseUserTagsLevel);
        ExcelUtil<BaseUserTagsLevelDO> util = new ExcelUtil<BaseUserTagsLevelDO>(BaseUserTagsLevelDO.class);
        return util.exportExcel(list, "level");
    }

    /**
     * 获取分级配置详细信息
     */
    @PreAuthorize("@ss.hasPermi('tag:level:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(baseUserTagsLevelService.selectBaseUserTagsLevelById(id));
    }

    /**
     * 新增分级配置
     */
    @PreAuthorize("@ss.hasPermi('tag:level:add')")
    @Log(title = "分级配置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BaseUserTagsLevelDO baseUserTagsLevel)
    {
        return toAjax(baseUserTagsLevelService.insertBaseUserTagsLevel(baseUserTagsLevel));
    }

    /**
     * 修改分级配置
     */
    @PreAuthorize("@ss.hasPermi('tag:level:edit')")
    @Log(title = "分级配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BaseUserTagsLevelDO baseUserTagsLevel)
    {
        return toAjax(baseUserTagsLevelService.updateBaseUserTagsLevel(baseUserTagsLevel));
    }

    /**
     * 删除分级配置
     */
    @PreAuthorize("@ss.hasPermi('tag:level:remove')")
    @Log(title = "分级配置", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(baseUserTagsLevelService.deleteBaseUserTagsLevelByIds(ids));
    }
}
